package com.management.springboot.controller;

import com.management.springboot.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

/**
 * @author scy
 * @Description
 * @date 2021/6/11-10:20
 */
@Controller
public class IndexController {
    @RequestMapping(value = "/" ,method = RequestMethod.GET)

    public String toLogin(){
        System.out.println("修改");
        System.out.println("提交到远程库后在修改");
         System.out.println("在gitee网页端修改之后pull");
        System.out.println("在hot-fix分支下的修改");
        return "login";
    }
@RequestMapping(value = "/login",method = RequestMethod.POST)
    public String toIndex(
        User user, HttpSession session, Model model){
        //调用service层
       //调用dao层
String username= user.getUsername();
String password=user.getPassword();
if(username.equals("admin")&&password.equals("123456")) {

   session.setAttribute("user",user);//保存到session中
    return "redirect:/main.html";//请求重定向到main
}else {
    model.addAttribute("msg","账号或密码错误");
    return "login";
}
}
@RequestMapping(value="/main.html")
public String toMain(){
        //虽然上上面验证了账号和密码，但是在浏览器之间输入该页面的url，仍可以访问，所以需要设置登录拦截器
        return "main";//重定向的请求交给该controller处理

}


}
